package arocms.business;

import java.io.Serializable;
import java.sql.Blob;

import org.hibernate.Session;
import arocms.util.*;
import java.util.List;
import org.apache.log4j.*;

public class File implements Serializable{
    
    private Long id;
    private String title;
    private String description;
    private String filename;
    private String filetype;
    private String filesize;
    private Blob filebin;
    
    private static Logger log = Logger.getLogger(File.class);
    
    public File() {
    }
    
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public String getFilename() {
        return filename;
    }
    
    public void setFilename(String filename) {
        this.filename = filename;
    }
    
    public String getFiletype() {
        return filetype;
    }
    
    public void setFiletype(String filetype) {
        this.filetype = filetype;
    }
    
    public String getFilesize() {
        return filesize;
    }
    
    public void setFilesize(String filesize) {
        this.filesize = filesize;
    }
    
    public Blob getFilebin() {
        return filebin;
    }
    
    public void setFilebin(Blob filebin) {
        this.filebin = filebin;
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
/*    
    public void persist() {
        Session sess = HibernateUtil.getSessionFactory().getCurrentSession();
        sess.beginTransaction();
        log.info("Storing file: " + getFiletype() + " " + getFilename());
        sess.save(this);
        if (getId()==null) log.error("File not added. Identiefier not assigned.");
        else log.debug("Generated id: " + String.valueOf(getId()));
        sess.getTransaction().commit();
        log.debug("Commited.");
    }
  */
    
    /*
    public static List getFiles() {
        Session sess = HibernateUtil.getSessionFactory().getCurrentSession();
        sess.beginTransaction();
        List files = sess.createQuery("select f.id, f.filename, f.filesize from File as f order by f.title asc").list();
        sess.getTransaction().commit();
        return files;
    }*/

//    public static FileDetails getFileDetails(Long id) {
//        FileDetails details = new FileDetails();
//        Session sess = HibernateUtil.getSessionFactory().getCurrentSession();
//        sess.beginTransaction();
//        File f = (File) sess.load(File.class,id);
//        FileDetails fd = new FileDetails();
/*
        if (files == null )  { log.error("files==null"); }
        if (files.size()==0) { log.error("No files with id equal " + String.valueOf(id)); }
*/
//        
//        fd.setId(f.getId());
//        fd.setTitle(f.getTitle());
//        fd.setDescription(f.getDescription());
//        fd.setFilename(f.getFilename());
//        fd.setFilesize(f.getFilesize());
//        fd.setFiletype(f.getFiletype());
//        sess.getTransaction().commit();
//        return fd;
//    }
//
//    public static File getFile(Long id) {
//        Session sess = HibernateUtil.getSessionFactory().getCurrentSession();
//        sess.beginTransaction();
//        //File f = (File) sess.load(File.class,id);
//        File f = (File) sess.createQuery("from File where id=" + id).uniqueResult();
//        sess.getTransaction().commit();
//        return f;
//    }
}
